home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15078 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: delete or delete [] ?
  5. Date: 3 Apr 1996 14:46:40 GMT
  6. Organization: Netcom
  7. Message-ID: <4ju30g$96q@cloner2.ix.netcom.com>
  8. References: <4jpe5j$3vo@doc.zippo.com>
  9. NNTP-Posting-Host: den-co11-06.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Wed Apr 03  6:46:40 AM PST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. >Actually it is quite simple, if the object is not an array, use delete; if it
  16. >is an array use delete [].
  17. >
  18. >You example works, and so will any example, is because of the way deallocating
  19. >a memory location occupy by an object and an array is just the same. The difference
  20. >between delete and delete[] is that delete [] will call the destructor for each
  21. >item in the array. Because int doesn't have a destructor, so it doesn't matter
  22. >if you use delete or delete[].
  23. >Clarence Chiang
  24.  
  25. Please be careful giving advice on this!  The operators delete and delete[] need not 
  26. be implemented identically, especially since in the ANSI draft (and I believe the 
  27. ARM?) one can override one operator pair (new/delete or new[]/delete[]) without the 
  28. overriding the other.  In addition, some implementations of new[]/delete[] allocate 
  29. data preceding the returned memory pointer to keep track of the number and size of 
  30. the objects in the array.
  31.  
  32. The rule is:  if you allocate with new[], then free with delete[].
  33. In your example, I believe that operator new[] is called for allocation,
  34. since the type is an array, so call operator delete[] to free it.
  35.  
  36. john lilley
  37.  
  38.  
  39.  
  40.